﻿Imports System
Imports System.Data.OleDb

Public Class DAL_InDeThiVaDapAn

    Public conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\10650_000\Desktop\ltudql1-doan\Database\Database.mdb"

    Public Function TaoCauHoiChoDe1(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.NoiDung desc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Function TaoCauHoiChoDe2(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.NoiDung asc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Function TaoCauHoiChoDe3(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.MaCauHoi desc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Function TaoCauHoiChoDe4(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.MaCauHoi asc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Sub LuuDeThiXuongDatatableDeTienHanhInDeVaDapAnTuongUng(ByVal cauhoi As String, ByVal noidung As String, ByVal a As String, ByVal b As String, ByVal c As String, ByVal d As String, ByVal dung As String)

        Dim StrSql As String

        StrSql = " Insert into DeThi_DapAn (cauhoi,noidung,a,b,c,d,dung) values (@cauhoi,@noidung,@a,@b,@c,@d,@dung)  "

        Dim con As New OleDbConnection(conn)

        Dim cmd As New OleDbCommand(StrSql, con)

        With cmd.Parameters

            .Add("@cauhoi", OleDbType.VarChar).Value = cauhoi

            .Add("@noidung", OleDbType.VarChar).Value = noidung

            .Add("@a", OleDbType.VarChar).Value = a

            .Add("@b", OleDbType.VarChar).Value = b

            .Add("@c", OleDbType.VarChar).Value = c

            .Add("@d", OleDbType.VarChar).Value = d

            .Add("@dung", OleDbType.VarChar).Value = dung

        End With

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()

    End Sub

    Function XoaDuLieuTrongBangDeThi_DapAn() As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = "Delete * from DeThi_DapAn"

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

End Class

